package cn.rongdao.jrkabao.ui.main.mainfragment.personal;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.mifengkong.frtools.http.request.callback.FRBaseObserver;
import com.mifengkong.frtools.ui.activity.FRStartActivity;
import com.mifengkong.frtools.ui.adapter.recyclerview.FRBaseRecyclerAdapter;
import com.mifengkong.frwidget.recyclerview.PtrRecyclerViewUIComponent;
import com.mifengkong.frwidget.refersh.OnPullToRefreshListener;
import com.mifengkong.frwidget.titlebar.TitleBarUIComponent;

import java.util.List;

import butterknife.BindView;
import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.base.BaseAutoFinishActivity;
import cn.rongdao.jrkabao.bean.main.personal.CompleteDataBean;
import cn.rongdao.jrkabao.model.main.personal.CompleteDataModel;
import cn.rongdao.jrkabao.ui.main.mainfragment.adapter.CompleteDataAdapter;
import cn.rongdao.jrkabao.ui.main.mainfragment.adapter.CompleteDataViewHolder;

/**
 * Created by jack on 2018/4/19
 */

public class CompleteDataActivity extends BaseAutoFinishActivity implements FRBaseRecyclerAdapter.OnItemClickListener<CompleteDataViewHolder> {

    public static void start(Context context) {
        FRStartActivity.start(context, CompleteDataActivity.class);
    }

    @BindView(R.id.acd_titlebar)
    TitleBarUIComponent titleBarUIComponent;
    @BindView(R.id.acd_ptr_framelayout)
    PtrRecyclerViewUIComponent ptrRecyclerViewUIComponent;
    private CompleteDataAdapter adapter;

    @Override
    protected int layoutRes() {
        return R.layout.activity_complete_data;
    }

    @Override
    protected void initView() {
        super.initView();
        initTitleBar();
        initPtr();
    }

    private void initPtr() {
        adapter = new CompleteDataAdapter(this, this);
        ptrRecyclerViewUIComponent.setLayoutManager(new LinearLayoutManager(this));
        ptrRecyclerViewUIComponent.setAdapter(adapter);
        ptrRecyclerViewUIComponent.delayRefresh();
        ptrRecyclerViewUIComponent.setOnPullToRefreshListener(new OnPullToRefreshListener() {
            @Override
            public void onPullToRefresh() {
                initData();
            }
        });
    }

    private void initData() {
        CompleteDataModel.getInstance().execute(new FRBaseObserver<List<CompleteDataBean>>(this) {
            @Override
            protected void onBaseNext(List<CompleteDataBean> data) {
                adapter.setDataList(data);
                ptrRecyclerViewUIComponent.refreshComplete();
            }

            @Override
            protected void onBaseError(Throwable t) {
                super.onBaseError(t);
                ptrRecyclerViewUIComponent.refreshComplete();
            }
        });
    }

    private void initTitleBar() {
        titleBarUIComponent.initTitle("认证资料补全");
        titleBarUIComponent.setBackgroundColor(ContextCompat.getColor(thisActivity(), R.color.colorPrimary));
        titleBarUIComponent.initLeftBack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void onItemClick(CompleteDataViewHolder completeDataViewHolder, int position) {

    }
}
